package com.cube.dp.base.response;

import com.cube.dp.base.error.CommonApiResultCode;
import lombok.Getter;

/**
 * @param <T> 响应实体类型
 * @author cube.li
 * @date 2021/12/5 15:48
 * <p>
 * 接口响应结果
 */
@Getter
public class ApiResult<T> {

    private int code;

    private String msg;

    private T data;

    private long timestamp;

    public ApiResult(int code, String msg, T data) {
        this.code = code;
        this.data = data;
        this.msg = msg;
        this.timestamp = System.currentTimeMillis();
    }

    public static <T> ApiResult<T> success(T data) {
        return new ApiResult<>(CommonApiResultCode.SUCCESS.getCode(), null, data);
    }

    public static ApiResult<Void> success() {
        return success(null);
    }

    public static ApiResult<Void> error(int code, String msg) {
        return new ApiResult<>(code, msg, null);
    }
}
